#!/bin/bash

# Define an array of concurrency levels
concurrency_levels=(1 10 20 30 40 50 60 70 80 90 100 120 140 150 200)

# Set other fixed parameters
model="qwen"
url="http://localhost:8000/v1/chat/completions"
service_kind="openai"
api_key="xxx"
dataset_path="open_qa.jsonl"
dataset="openqa"
read_timeout=1200
log_every_n_query=10
stream="--stream"

# Define the base directory for output reports
outputs_base_dir="./h200_output"

# Create a log file
log_file="genai_perf_log.txt"
echo "Logging output to $log_file" > $log_file

# Iterate over each concurrency level
for concurrency in "${concurrency_levels[@]}"; do
  # Calculate the number based on concurrency
  number=$((concurrency * 10))
  echo "Running evalscope perf with concurrency: $concurrency and number: $number" | tee -a $log_file

  # Dynamically generate the artifact-dir path
  outputs_dir="${outputs_base_dir}/${model}-concurrency${concurrency}"
  mkdir -p "$outputs_dir"  # Ensure the directory exists

  # Run the command and record output with tee
  evalscope perf \
    --url "$url" \
    --parallel "$concurrency" \
    --model "$model" \
    --number "$number" \
    --log-every-n-query "$log_every_n_query" \
    --read-timeout="$read_timeout" \
    --dataset-path "$dataset_path" \
    --api "$service_kind" \
    --dataset "$dataset" \
    --outputs-dir "$outputs_dir" \
    --api-key "$api_key" \
    $stream | tee -a $log_file

  # Only sleep if there are more items to process
  if [[ $concurrency -ne ${concurrency_levels[-1]} ]]; then
    echo "Sleeping for 30 seconds..." | tee -a $log_file
    sleep 30
  fi
done

echo "All tasks completed." | tee -a $log_file